#include "stdafx.h"
#include "wf_printpreview.h"

/**
 * Constructor.
 */
WF_PrintPreview::WF_PrintPreview(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Print Preview",
                    container, graphicView) {
    showOptions();
}



WF_PrintPreview::~WF_PrintPreview() {
}


QAction* WF_PrintPreview::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("Print Preview")
	QAction* action = new QAction(tr("Print Pre&view"), NULL);
#if QT_VERSION >= 0x040600
        action->setIcon(QIcon::fromTheme("document-print-preview", QIcon(":/actions/fileprintpreview.png")));
#else
        action->setIcon(QIcon(":/actions/fileprintpreview.png"));
#endif
        //action->zetStatusTip(tr("Shows a preview of a print"));
	return action;
}


void WF_PrintPreview::init(int status) {
    PF_ActionInterface::init(status);
    showOptions();
}




void WF_PrintPreview::trigger() {}



void WF_PrintPreview::mouseMoveEvent(PF_MouseEvent* e) {
	switch (getStatus()) {
	case Moving:
		v2 = graphicView->toGraph(e->x(), e->y());
		if (graphic!=NULL) {
			PF_Vector pinsbase = graphic->getPaperInsertionBase();
			
			double scale = graphic->getPaperScale();
			
			graphic->setPaperInsertionBase(pinsbase-v2*scale+v1*scale);
		}
		v1 = v2;
			graphicView->redraw(LX_Define::RedrawGrid); // DRAW Grid also draws paper, background items
		break;

	default:
		break;
	}
}



void WF_PrintPreview::mousePressEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::LeftButton) {
        switch (getStatus()) {
        case Neutral:
            v1 = graphicView->toGraph(e->x(), e->y());
            setStatus(Moving);
            break;

        default:
            break;
        }
    }
}


void WF_PrintPreview::mouseReleaseEvent(PF_MouseEvent* e) {
	switch (getStatus()) {
	case Moving:
		setStatus(Neutral);
		break;
		
    default:
        PF_DIALOGFACTORY->requestPreviousMenu();
        e->accept();
        break;
	}
}



void WF_PrintPreview::coordinateEvent(PF_CoordinateEvent* ) {}



void WF_PrintPreview::commandEvent(PF_CommandEvent* ) {}



PF_StringList WF_PrintPreview::getAvailableCommands() {
    PF_StringList cmd;
    return cmd;
}


void WF_PrintPreview::showOptions() {
    PF_ActionInterface::showOptions();

    PF_DIALOGFACTORY->requestOptions(this, true);
}



void WF_PrintPreview::hideOptions() {
    PF_ActionInterface::hideOptions();

    PF_DIALOGFACTORY->requestOptions(this, false);
}


void WF_PrintPreview::updateMouseButtonHints() {}



void WF_PrintPreview::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::MovingHandCursor);
}



void WF_PrintPreview::updateToolBar() {}


void WF_PrintPreview::center() {
    if (graphic!=NULL) {
        graphic->centerToPage();
        graphicView->redraw();
    }
}


void WF_PrintPreview::fit() {
    if (graphic!=NULL) {
        graphic->fitToPage();
        graphicView->redraw();
    }
}


void WF_PrintPreview::setScale(double f) {
    if (graphic!=NULL) {
		graphic->setPaperScale(f);
    	graphicView->redraw();
	}
}



double WF_PrintPreview::getScale() {
	double ret = 1.0;
    if (graphic!=NULL) {
		ret = graphic->getPaperScale();
	}
	return ret;
}



void WF_PrintPreview::setBlackWhite(bool bw) {
    if (bw) {
        graphicView->setDrawingMode(LX_Define::ModeBW);
    }
	else {
        graphicView->setDrawingMode(LX_Define::ModeFull);
	}
	graphicView->redraw();
}


LX_Define::Unit WF_PrintPreview::getUnit() {
    if (graphic!=NULL) {
		return graphic->getUnit();
	}
	else {
		return LX_Define::None;
	}
}


// EOF
